<template>
  <el-dialog
      title="Bug反馈"
      :width="450"
      :show-close="false"
      :close-on-click-modal="false"
      center>
    <el-form :model="this.bug" :rules="bugRules" ref="bugRules">
      <el-form-item label="出现的模块" prop="model">
        <el-input v-model="this.bug.model" placeholder="请输入出现问题的模块名称"></el-input>
      </el-form-item>
      <el-form-item label="遇到的问题" prop="content">
        <el-input
            v-model="this.bug.content"
            style="width: 440px"
            :rows="5"
            type="textarea"
            placeholder="请详细描述遇到的问题"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="cancelClick('bugRules')">取消</el-button>
      <el-button type="primary" @click="confirmBug('bugRules')">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import request from "@/util/request.js";
import {ElMessage} from "element-plus";

export default {
  name: "bugRelated",
  data() {
    return {
      bug: {},
      bugRules: {
        model: [
          {required: true, message: '请输入模块名称', trigger: 'blur'}
        ],
        content: [
          {required: true, message: '请输入遇到的问题', trigger: 'blur'}
        ]
      },
    }
  },
  methods: {
    cancelClick(bugRules) {
      this.$store.commit('bugDialogShow')
      this.bug = {}
      this.bug.studentAccountNo=JSON.parse(localStorage.getItem('user')).accountNo
      this.$refs[bugRules].resetFields();
    },
    confirmBug() {
      this.$refs.bugRules.validate((valid) => {
        if (valid) {
          this.bug.type = "1"
          this.$confirm(' 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'info'
          }).then(() => {
            this.bug.studentAccountNo=JSON.parse(localStorage.getItem('user')).accountNo
            this.$store.commit('bugDialogShow')
            request.post("/related_feedback/edit", this.bug).then(res => {
              if (res.data.data) {
                this.bug = {}
                this.bug.studentAccountNo=JSON.parse(localStorage.getItem('user')).accountNo
                ElMessage({
                  type: 'success',
                  message: '成功提交，感谢反馈!'
                });
              }
            })
          })
        } else {
          ElMessage({
            type: 'warning',
            message: "请输入内容"
          });
        }
      });
    },
  }
}
</script>

<style scoped>
.dialog-footer {
  text-align: center;
}
</style>
